/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.dozor;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 *
 * @author amalikov
 */
public class PowerModule implements MessagePayload {
	public byte connect;
	public byte flags;
	public short uin;
	public short uout;
	public short ibat;
	public short iout;
	public short tmod;
	public short tbat;

	@Override
	public byte[] get() {
		ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
		bb.put(connect);
		bb.put(flags);
		bb.putShort(uin);
		bb.putShort(uout);
		bb.putShort(ibat);
		bb.putShort(iout);
		bb.putShort(tmod);
		bb.putShort(tbat);
		return Arrays.copyOf(bb.array(), bb.position());
	}

	@Override
	public void set(byte[] data) {
		ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
		connect = bb.get();
		flags = bb.get();
		uin = bb.getShort();
		uout = bb.getShort();
		ibat = bb.getShort();
		iout = bb.getShort();
		tmod = bb.getShort();
		tbat = bb.getShort();
	}
	
}
